<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{id?'编辑':'添加'}}配置信息</legend>
        </fieldset>
        <form class="layui-form" action="" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">服务器ID</label>
                <div class="layui-input-block">
                    <input type="text" name="serverId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"  readonly>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input"  readonly>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">关闭模式</label>
                <div class="layui-input-block">
                    <input type="text" name="closeType" placeholder="请输入" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">开启等级</label>
                <div class="layui-input-block">
                    <input type="text" name="openLevel" placeholder="请输入"  class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">开启类型(1.付费 2.小月卡 3.大月卡)</label>
                <div class="layui-input-block">
                    <input type="text" name="openType" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">值1(1:货币类型)</label>
                <div class="layui-input-block">
                    <input type="text" name="openValue1" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">值2</label>
                <div class="layui-input-block">
                    <input type="text" name="openValue2" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否关闭吃鸡[0:否,1:是]</label>
                <div class="layui-input-block">
                    <input type="text" name="isCloseChiji" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否关闭竞技场[0:否,1:是]</label>
                <div class="layui-input-block">
                    <input type="text" name="isCloseArena" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否关闭竞技场[0:否,1:是]</label>
                <div class="layui-input-block">
                    <input type="text" name="isCloseCrossserver" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>

    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script src="/xm-select-v1.2.4/xm-select.js"></script>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    var serverids = JSON.parse(localStorage.getItem('services'))

    var Id = urlParam('id')
    var ids = urlParam('ids')

    var form = null;
    new Vue({
        el:"#app",
        data:{
            id:Id,
            serverGroups:[],
            formData:{
                show:null,
                status:null,
                busy_status:null,
                pay_status:null,
                white_status:"0",
                id:null
            }
        },
        updated:function(){
            form.render();
        },
        methods:{

        },
        mounted:function() {
            var _this = this;
            layui.use(['form', 'laydate'], function () {
                form = layui.form;
                var layer = layui.layer, $ = layui.$,laydate=layui.laydate;
                laydate.render({
                    elem: '#enable_at',
                    type: 'datetime',
                    trigger: 'click'
                });


                var dataSg = [];
                for(var k in serverids){
                    var v = serverids[k];
                    dataSg.push({
                        name:v.name,
                        value:v.server_id,
                    })
                }

                xmSelect.render({
                    el: '#serverids',
                    name:"serverids",
                    language: 'zn',
                    data: dataSg,
                    multiple: true,// 确保开启多选

                })




                if (Id) {
                    $.get('/admin/funtionOpen/' + Id, {ids: ids}, function (res) {
                        var data = res.data;
                        _this.formData = data;
                        console.log('查看传过来的ID',data)
                        _this.id = data.id;

                        var waiting = setInterval(function () {
                               form.val('example', {
                                   "serverId": Id,
                                   "name": data.name,
                                   "closeType": data.close_type,
                                   "openLevel": data.open_level,
                                   "openType": data.open_type,
                                   "openValue1": data.open_value1,
                                   "openValue2": data.open_value2,
                                   "isCloseChiji": data.is_close_chiji,
                                   "isCloseArena": data.is_close_arena,
                                   "isCloseCrossserver": data.is_close_crossserver
                               })
                               clearInterval(waiting)
                        },1)
                    })
                    //表单初始赋值
                }
                //监听提交
                form.on('submit(demo1)', function (data) {
                    var formData = data.field;

                    console.log('查看传过来的ID',Id)
                    if (Id) {

                        formData._method = 'put';
                        formData.id=_this.id;
                        $.post('/admin/funtionOpen/' + Id, formData, function (res) {
                            if (res.code === 0) {
                                layer.msg('success', {icon: 6, time: 500}, function () {
                                    parent.location.reload();//父页面刷新
                                })
                            } else {
                                layer.msg(res.msg, {icon: 5})
                            }
                        })
                    } else { //add
                        $.post('/admin/funtionOpen/add', formData, function (res) {
                            if (res.code === 0) {
                                layer.msg('success', {icon: 6, time: 500}, function () {
                                    parent.location.reload();//父页面刷新
                                })
                            } else {
                                layer.msg(res.msg, {icon: 5})
                            }
                        })
                    }

                    return false;
                });
                form.on('radio(status)',function(data){
                    _this.formData.status = data.value;
                })
                form.render();
            })
        }
    });
</script>

</body>
</html>